package main

import (
	"github.com/gin-gonic/gin"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	"log"
	"zg5/videos/api-gateway/router"
	"zg5/videos/common/global"
	"zg5/videos/common/inits"
	"zg5/videos/common/proto/users"
	"zg5/videos/common/proto/videos"
)

func main() {
	inits.GetViper()
	inits.InitNacos()
	UserGrpc()
	VideosGrpc()

	r := gin.Default()
	router.LoadRouter(r)
	r.Run()
}

func UserGrpc() {
	conn, err := grpc.NewClient("localhost:8899", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}
	global.UserGrpc = users.NewUserSrvClient(conn)
}
func VideosGrpc() {
	conn, err := grpc.NewClient("localhost:8880", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}
	global.VideosGrpc = videos.NewVideoSrvClient(conn)
}
